Python Game Programming By Example by Unknown

Python Game Programming By Example by Unknown
Author: Unknown
Language: eng
Format: epub, mobi
Publisher: Packt Publishing

Tip


Lighting and colors

When lighting is enabled, the colors are not determined by the glColor functions but by the combination of the lighting computation and the material colors set by glMaterial. To combine lighting with glColor, it is required that you enable GL_COLOR_MATERIAL first:

glEnable(GL_COLOR_MATERIAL) # ... glColor4f(r, g, b, a) # Draw polygons

Once we have initialized GLUT and enabled the GL capabilities, we complete our start() method by specifying the clear color, setting the perspective, and starting the main loop:

def start(self): # ... glClearColor(.1, .1, .1, 1) glMatrixMode(GL_PROJECTION) aspect = self.width / self.height gluPerspective(40., aspect, 1., 40.) glMatrixMode(GL_MODELVIEW) glutDisplayFunc(self.display) glutSpecialFunc(self.keyboard) glutMainLoop() def keyboard(self, key, x, y): pass